package com.ruibang.glass.quality.controller.manage;

import com.ruibang.glass.frequencycontrol.annotation.FrequencyControl;
import com.ruibang.glass.quality.domain.req.ParticlePlotReq;
import com.ruibang.glass.quality.service.ParticlePlotService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-12-01  15:07
 * @Description: TODO:质量管理：颗粒点图
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api/quality/manage/particlePlot")
@Api(value = "颗粒点图（冷端）", tags = {"颗粒点图（冷端）"})
public class ParticlePlotController {

    @Autowired
    private ParticlePlotService particlePlotService;

    @PostMapping("/queryColdPoint")
    @ApiOperation(value = "颗粒点图", notes = "颗粒点图")
    public ResultBody queryColdPoint(@RequestBody @Valid ParticlePlotReq particlePlotReq) {
        return ResultBody.success(particlePlotService.queryColdPoint(particlePlotReq));
    }

    @PostMapping("/queryColdLineChart")
    @ApiOperation(value = "颗粒折线图(包含堆积图)", notes = "颗粒折线图(包含堆积图)")
    public ResultBody queryColdLineChart(@RequestBody ParticlePlotReq particlePlotReq) {
        return ResultBody.success(particlePlotService.queryColdLineChart(particlePlotReq));
    }

    @PostMapping("/export")
    @FrequencyControl(time = 15, count = 2, target = FrequencyControl.Target.IP)
    @FrequencyControl(time = 30, count = 5, target = FrequencyControl.Target.IP)
    @ApiOperation(value = "导出颗粒数据", notes = "导出颗粒数据")
    public void export(@RequestBody ParticlePlotReq particlePlotReq, HttpServletResponse response) {
        particlePlotService.export(particlePlotReq, response);
    }
}
